define([
  'jquery',
  'underscore',
  'backbone',
  'lightboxme',
  'dateformatter',
  'models/appointment/AppointmentModel',
  'text!templates/appointments/patientAppointmentTemplate.html'
], function($, _, Backbone,LightBoxMe,Dateformatter, AppointmentModel, appointmentTemplate){

  var PatientView = Backbone.View.extend({
    el: $(".modal"),
    events: {'click .actions' : 'close'} ,
    render: function(event,readonly){
		 var appointmentId = $(event.target).attr('appointmentid');
		 var appointmentModel = new AppointmentModel({id:appointmentId});
	        var lOptions = {};
	        var self=this;
	        lOptions.success = function(){
			      var data = {
			    	        appointment: appointmentModel,
			    	        readonly:readonly
			    	      };
			      self.loadTemplate(data);

	        };
			 appointmentModel.fetch(lOptions);


    },
    loadTemplate: function(data){
	      var compiledTemplate = _.template( appointmentTemplate, data );
	      this.$el.html(compiledTemplate);
        $(".modal").lightbox_me({centered: true, onLoad: function() {
			$("#modal_window").find("input:first").focus();
		}
        });
    	
    },
    close: function(){
    	
    }
  });

  return PatientView;
});
